<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>重复匹配对原子组的影响（匹配电话号码）</title>
</head>
<body>
    <input type="text" name="number">
    <span></span>
</body>
<script>
    /*
        匹配电话号码  电话号码都是由3-4位区号加上-和7-8为数字组成
    */
    const span = document.getElementsByTagName('span')[0]
    const input = document.querySelector(`[name = "number"]`)
    const reg = /^0\d{2,3}-\d{7,8}$/
    const str = "0478-99999999"
    console.log(str.match(reg))
    input.addEventListener('keyup',function(){
        const reg = /^0\d{2,3}-\d{7,8}$/
        console.log(reg.test(input.value))
        if(reg.test(input.value)){
            span.innerHTML = '正确'
        }else{
            span.innerHTML = '失败'
        }
    })
</script>
</html>